package com.ygp.lock.rlock;

public class MyObject {
    public static void main(String[] args) {
        MyObject object = new MyObject();
        object.increase();
        object.decrease();
    }

    private int counter;

    public synchronized void increase() {
        while (counter != 0) {
            try {
                wait();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }

        counter++;

        System.out.println(counter);

        notify();
    }

    public synchronized void decrease() {
        while (counter == 0) {
            try {
                wait();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }

        counter--;

        System.out.println(counter);

        notify();
    }
}
